package cn.wen.yinxiu.works.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import cn.wen.yinxiu.common.convention.result.Results;
import cn.wen.yinxiu.common.to.es.TopicEsModel;
import cn.wen.yinxiu.common.to.works.TopicTO;
import cn.wen.yinxiu.works.vo.TopicInfoVO;
import cn.wen.yinxiu.works.vo.TopicSimpleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.wen.yinxiu.works.entity.TopicEntity;
import cn.wen.yinxiu.works.service.TopicService;
import cn.wen.yinxiu.common.toolkit.PageUtils;
import cn.wen.yinxiu.common.convention.result.ResultEntity;

/**
 *
 * @ClassName: TopicController
 * @Author 小飞
 * @Email coderwen22@163.com
 * @Date 2023-05-22 09:39:56
 * @Description: 作品话题详情表的Controller层
 */
@RestController
@RequestMapping("/web")
public class TopicController {

    @Autowired
    private TopicService topicService;

    /**
     * 获取最热话题前20
     *
     * @return
     */
    @GetMapping("/api/works/topic/hot/list")
    public ResultEntity getHotTopicList() {
        List<TopicInfoVO> topicList = topicService.queryTopicHotList();
        return Results.success(topicList);
    }

    /**
     * TODO 更新话题浏览数（存储到Redis 然后再实现后台更新）
     *
     * @return
     */
    @PostMapping("/api/works/topic/update/view")
    public ResultEntity referenceTopic(@RequestBody List<TopicTO> topicList) {
        boolean res = topicService.updateTopicViewList(topicList);
        if (!res) return Results.failure();
        return Results.success();
    }

    /**
     * 模糊查询前15个热度  播放热度
     * @param keyword
     * @return
     */
    @GetMapping("/api/works/topic/search/list")
    public ResultEntity getTopicList(@RequestParam("keyword") String keyword) {
        List<TopicInfoVO> resList = topicService.searchTopicList(keyword);
        return Results.success(resList);
    }

    @GetMapping("/api/works/topic/guess/list")
    public ResultEntity getTopicGuessSearch(@RequestParam("keyword") String keyword) {
        List<TopicEsModel> guessTopicList = topicService.getTopicGuessSearch(keyword);
        return Results.success(guessTopicList);
    }

}
